package com.woniu.web.servlet;

import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.woniu.domain.Order;
import com.woniu.domain.ShopCart;
import com.woniu.domain.User;
import com.woniu.domain.UserAddress;
import com.woniu.service.UserService;
import com.woniu.service.impl.UserServiceImpl;

/**
 * Servlet implementation class OrderServlet
 */
@WebServlet("/OrderServlet")
public class OrderServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public OrderServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//		UserService us = new UserServiceImpl();
//		CategoryService cs = new CategoryServiceImpl();
//		User user = new User();
//		Order order = new Order();
//		cs.getOrder(order.getOrderNum());
//		
//		request.setAttribute("user", user);
		//ShopCart shop = new ShopCart();
		UserService us = new UserServiceImpl();
		Order order = new Order();
		User user = null;
		try {
			user = us.findAllUser();
			String orderNum = order.getOrderNum();
			request.setAttribute("orderNum", orderNum);
			List<UserAddress> addresslist = us.findUserAddress(user);
			//System.out.println(address.getAddress());
			request.setAttribute("addresslist", addresslist);
			HttpSession session = request.getSession();
			ShopCart shopCart = (ShopCart) session.getAttribute("shopCart");
			request.setAttribute("shopCart", shopCart);
			request.getRequestDispatcher("order.jsp").forward(request, response);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
